<?php
class tbl_log extends AppModel
{
    public $useTable = 'log_gm_admin';
    public $useDbConfig = 'fantasy_hero_kr_log';
    public $primaryKey = '_id';

    public function get_log_list()
    {
        $conditions = '';
        if(CakeSession::read('login_session.admin_auth') >= AUTH_DEVELOPER)
        {
            $conditions = '';
        }

        $params = array(
            'conditions' => $conditions,
            'order' => array('update_time' => 'DESC')
        );

        $data = $this->find('all', $params);

        foreach($data as $num => $log_list)
        {
            $data[$num]['connection_log']['before_data'] = json_decode($log_list['connection_log']['before_data'], true);
            $data[$num]['connection_log']['after_data'] = json_decode($log_list['connection_log']['after_data'], true);
        }

        return $data;
    }

    public function after_month_delete_log()
    {
        $params = array(
            /*'conditions' =>
                array(
                    'update_time <' => date('Y-m-d H:i:s', strtotime('-30 days'))
                ),*/
            'update_time <' => date("Y-m-d H:i:s", strtotime("-61 days"))
        );



        $this->deleteAll($params);
    }
}